using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Verben
{
	public class XmlZeug
	{
		private static VerbList mIrregular;
		public static VerbList Irregular
		{
			get
			{
				if (mIrregular == null)
				{
					mIrregular = new VerbList();
					XmlDocument xml = new XmlDocument();
					xml.Load("Irregulaer.xml");
					XmlNodeList verbs = xml.SelectNodes("//verbs/verb");
					foreach (XmlNode verbNode in verbs)
					{
						mIrregular.Add(VerbFromXml(verbNode));
					}
				}
				return mIrregular;
			}
		}

		public static Verb VerbFromXml(XmlNode node)
		{
			Verb v = new Verb();
			v.Infinitiv = node.Attributes[0].Value;
			XmlNode present = node.ChildNodes[0];
			v.Present.Ich = GetValue(present, 0);
			v.Present.Du = GetValue(present, 1);
			v.Present.Er = GetValue(present, 2);
			v.Present.Wir = GetValue(present, 3);
			v.Present.Ihr = GetValue(present, 4);
			v.Present.Sie = GetValue(present, 5);
			XmlNode past = node.ChildNodes[1];
			v.Past.Ich = GetValue(past, 0);
			v.Past.Du = GetValue(past, 1);
			v.Past.Er = GetValue(past, 2);
			v.Past.Wir = GetValue(past, 3);
			v.Past.Ihr = GetValue(past, 4);
			v.Past.Sie = GetValue(past, 5);
			return v;
		}

		private static string GetValue(XmlNode node, int index)
		{
			return node.ChildNodes[index].InnerText;
		}
	}
}
